package goodclass

import (
	
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/model/goodclass"
    goodclassReq "github.com/flipped-aurora/gin-vue-admin/server/model/goodclass/request"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
    "github.com/flipped-aurora/gin-vue-admin/server/utils"
)

type LsGoodClassApi struct {}



// CreateLsGoodClass 创建lsGoodClass表
// @Tags LsGoodClass
// @Summary 创建lsGoodClass表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body goodclass.LsGoodClass true "创建lsGoodClass表"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /lsGoodClass/createLsGoodClass [post]
func (lsGoodClassApi *LsGoodClassApi) CreateLsGoodClass(c *gin.Context) {
	var lsGoodClass goodclass.LsGoodClass
	err := c.ShouldBindJSON(&lsGoodClass)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
    lsGoodClass.CreatedBy = utils.GetUserID(c)
	err = lsGoodClassService.CreateLsGoodClass(&lsGoodClass)
	if err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("创建成功", c)
}

// DeleteLsGoodClass 删除lsGoodClass表
// @Tags LsGoodClass
// @Summary 删除lsGoodClass表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body goodclass.LsGoodClass true "删除lsGoodClass表"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /lsGoodClass/deleteLsGoodClass [delete]
func (lsGoodClassApi *LsGoodClassApi) DeleteLsGoodClass(c *gin.Context) {
	ID := c.Query("ID")
    userID := utils.GetUserID(c)
	err := lsGoodClassService.DeleteLsGoodClass(ID,userID)
	if err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeleteLsGoodClassByIds 批量删除lsGoodClass表
// @Tags LsGoodClass
// @Summary 批量删除lsGoodClass表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /lsGoodClass/deleteLsGoodClassByIds [delete]
func (lsGoodClassApi *LsGoodClassApi) DeleteLsGoodClassByIds(c *gin.Context) {
	IDs := c.QueryArray("IDs[]")
    userID := utils.GetUserID(c)
	err := lsGoodClassService.DeleteLsGoodClassByIds(IDs,userID)
	if err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdateLsGoodClass 更新lsGoodClass表
// @Tags LsGoodClass
// @Summary 更新lsGoodClass表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data body goodclass.LsGoodClass true "更新lsGoodClass表"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /lsGoodClass/updateLsGoodClass [put]
func (lsGoodClassApi *LsGoodClassApi) UpdateLsGoodClass(c *gin.Context) {
	var lsGoodClass goodclass.LsGoodClass
	err := c.ShouldBindJSON(&lsGoodClass)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
    lsGoodClass.UpdatedBy = utils.GetUserID(c)
	err = lsGoodClassService.UpdateLsGoodClass(lsGoodClass)
	if err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:" + err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindLsGoodClass 用id查询lsGoodClass表
// @Tags LsGoodClass
// @Summary 用id查询lsGoodClass表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param ID query uint true "用id查询lsGoodClass表"
// @Success 200 {object} response.Response{data=goodclass.LsGoodClass,msg=string} "查询成功"
// @Router /lsGoodClass/findLsGoodClass [get]
func (lsGoodClassApi *LsGoodClassApi) FindLsGoodClass(c *gin.Context) {
	ID := c.Query("ID")
	relsGoodClass, err := lsGoodClassService.GetLsGoodClass(ID)
	if err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:" + err.Error(), c)
		return
	}
	response.OkWithData(relsGoodClass, c)
}
// GetLsGoodClassList 分页获取lsGoodClass表列表
// @Tags LsGoodClass
// @Summary 分页获取lsGoodClass表列表
// @Security ApiKeyAuth
// @Accept application/json
// @Produce application/json
// @Param data query goodclassReq.LsGoodClassSearch true "分页获取lsGoodClass表列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /lsGoodClass/getLsGoodClassList [get]
func (lsGoodClassApi *LsGoodClassApi) GetLsGoodClassList(c *gin.Context) {
	var pageInfo goodclassReq.LsGoodClassSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := lsGoodClassService.GetLsGoodClassInfoList(pageInfo)
	if err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败:" + err.Error(), c)
        return
    }
    response.OkWithDetailed(response.PageResult{
        List:     list,
        Total:    total,
        Page:     pageInfo.Page,
        PageSize: pageInfo.PageSize,
    }, "获取成功", c)
}

// GetLsGoodClassPublic 不需要鉴权的lsGoodClass表接口
// @Tags LsGoodClass
// @Summary 不需要鉴权的lsGoodClass表接口
// @Accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /lsGoodClass/getLsGoodClassPublic [get]
func (lsGoodClassApi *LsGoodClassApi) GetLsGoodClassPublic(c *gin.Context) {
    // 此接口不需要鉴权
    // 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
    lsGoodClassService.GetLsGoodClassPublic()
    response.OkWithDetailed(gin.H{
       "info": "不需要鉴权的lsGoodClass表接口信息",
    }, "获取成功", c)
}
